#!/bin/bash
clear

TEXT='\033[30;107;2m'
INFO='\033[97;44m'
WARNING='\033[97;43m'
ERROR='\033[97;41m'
SUCCESS='\033[97;42m'
GREEN='\033[92m'
YELLOW='\033[93m'
RESET='\033[0m'

if [ "${EUID}" -ne 0 ]; then
	echo -e "${ERROR} RALAT ${RESET}${TEXT} Anda tiada kebenaran untuk menjalankan skrip ini! ${RESET}"; exit 1
fi

echo
echo -e "${TEXT} DROPBEAR - LOG MASUK KLIEN                                 ${RESET}"
echo
cat "/var/log/auth.log" | grep -i dropbear | grep -i "Password auth succeeded" > /tmp/dropbear_login.txt;
getServiceID=($( ps aux | grep -i dropbear | awk '{print $2}' ))
for dpi in "${getServiceID[@]}"
do
	cat /tmp/dropbear_login.txt | grep "dropbear\[$dpi\]" > /tmp/dropbear_login_pid.txt;
	getUserName=$(cat /tmp/dropbear_login_pid.txt | awk '{print $10}')
	getUserAddr=$(cat /tmp/dropbear_login_pid.txt | awk '{print $12}')
	totalClient=$(cat /tmp/dropbear_login_pid.txt | wc -l)
	[[ $totalClient -eq 1 ]] && echo "$dpi - $getUserName - $getUserAddr"
done
echo
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo -e "${TEXT} Created by Doctype, Powered by Cybertize.                  ${RESET}"
echo -e "${TEXT} Copyright 2021, Allright Reserved.                         ${RESET}"
echo -e "${TEXT} ========================================================== ${RESET}"
echo

echo
echo -e "${TEXT} OPENVPN - LOG MASUK KLIEN                                  ${RESET}"
echo
if [ -f "/var/log/openvpn/openvpn-auth.log" ]
then
	line=`cat /var/log/openvpn/openvpn-auth.log | wc -l`
	a=$(( 3 + ((line - 8) / 2) )) && b=$(( (line - 8) / 2 ))
	cat /var/log/openvpn/ovpn-auth.log | head -n $a | tail -n $b | cut -d "," -f 1,2,5 | sed -e 's/,/   /g' > /tmp/vpn-login-db.txt
	cat /tmp/vpn-login-db.txt
fi
echo
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo -e "${TEXT} Dicipta oleh Doctype, Dikuasakan oleh Cybertize.           ${RESET}"
echo -e "${TEXT} ========================================================== ${RESET}"
echo